﻿function VkApi_InitVK() {
    VK.init(function () {
        // Add calbacks
        VK.addCallback('onApplicationAdded', onApplicationAdded);
        VK.addCallback('onSettingsChanged', onSettingsChanged);
        VK.addCallback('onBalanceChanged', onBalanceChanged);
        VK.addCallback('onWindowBlur', onWindowBlur);
        VK.addCallback('onWindowFocus', onWindowFocus);

        // API initialization succeed
        element = document.getElementById('{0}');
        element.content.VkFacade.OnInitOk();

    }, function () {
        // API initialization failed
        element = document.getElementById('{0}');
        element.content.VkFacade.OnInitFailed();
    });
}

function translator(num) {
    return function (data) {
        callback(num, data);
    };
}

function callback(num, data) {
    element = document.getElementById('{0}');
    element.content.VkFacade.OnApiResponse(num, JSON.stringify(data));
}

function onApplicationAdded() {
    element = document.getElementById('{0}');
    element.content.VkFacade.OnApplicationAdded();
}

function onSettingsChanged(settings) {
    element = document.getElementById('{0}');
    element.content.VkFacade.OnSettingsChanged(settings);
}

function onBalanceChanged(balance) {
    element = document.getElementById('{0}');
    element.content.VkFacade.OnBalanceChanged(balance);
}

function onWindowBlur() {
    element = document.getElementById('{0}');
    element.content.VkFacade.OnWindowBlur();
}

function onWindowFocus() {
    element = document.getElementById('{0}');
    element.content.VkFacade.OnWindowFocus();
}